package com.dai.consumer_feign31.controller;

import com.dai.com_api.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;


@RestController
public class DeptController_Consumer {

//    private final String REST_URL="http://DAI-PROVIDER-3001";
    private static final String REST_URL="http://DAI-PROVIDER";

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/dept/add")
    public boolean add(@RequestBody Dept dept){
        return restTemplate.postForObject(REST_URL+"/dept/add",dept,Boolean.class);
    }

    @RequestMapping(value = "/dept/get/{id}",method = RequestMethod.GET)
    public Dept get(@PathVariable("id") int id){
        return restTemplate.getForObject(REST_URL+"/dept/get/"+id,Dept.class);
    }

    @RequestMapping("/dept/list")
    public List<Dept> list(){
        return restTemplate.getForObject(REST_URL+"/dept/list",List.class);
    }
}
